

class LocalConfigurationRegistryController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
        [ localConfigurationRegistryInstanceList: LocalConfigurationRegistry.list( params ), localConfigurationRegistryInstanceTotal: LocalConfigurationRegistry.count() ]
    }

    def show = {
        def localConfigurationRegistryInstance = LocalConfigurationRegistry.get( params.id )

        if(!localConfigurationRegistryInstance) {
            flash.message = "LocalConfigurationRegistry not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ localConfigurationRegistryInstance : localConfigurationRegistryInstance ] }
    }

    def delete = {
        def localConfigurationRegistryInstance = LocalConfigurationRegistry.get( params.id )
        if(localConfigurationRegistryInstance) {
            try {
                localConfigurationRegistryInstance.delete(flush:true)
                flash.message = "LocalConfigurationRegistry ${params.id} deleted"
                redirect(action:list)
            }
            catch(org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "LocalConfigurationRegistry ${params.id} could not be deleted"
                redirect(action:show,id:params.id)
            }
        }
        else {
            flash.message = "LocalConfigurationRegistry not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def localConfigurationRegistryInstance = LocalConfigurationRegistry.get( params.id )

        if(!localConfigurationRegistryInstance) {
            flash.message = "LocalConfigurationRegistry not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ localConfigurationRegistryInstance : localConfigurationRegistryInstance ]
        }
    }

    def update = {
        def localConfigurationRegistryInstance = LocalConfigurationRegistry.get( params.id )
        if(localConfigurationRegistryInstance) {
            if(params.version) {
                def version = params.version.toLong()
                if(localConfigurationRegistryInstance.version > version) {
                    
                    localConfigurationRegistryInstance.errors.rejectValue("version", "localConfigurationRegistry.optimistic.locking.failure", "Another user has updated this LocalConfigurationRegistry while you were editing.")
                    render(view:'edit',model:[localConfigurationRegistryInstance:localConfigurationRegistryInstance])
                    return
                }
            }
            localConfigurationRegistryInstance.properties = params
            if(!localConfigurationRegistryInstance.hasErrors() && localConfigurationRegistryInstance.save()) {
                flash.message = "LocalConfigurationRegistry ${params.id} updated"
                redirect(action:show,id:localConfigurationRegistryInstance.id)
            }
            else {
                render(view:'edit',model:[localConfigurationRegistryInstance:localConfigurationRegistryInstance])
            }
        }
        else {
            flash.message = "LocalConfigurationRegistry not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def create = {
        def localConfigurationRegistryInstance = new LocalConfigurationRegistry()
        localConfigurationRegistryInstance.properties = params
        return ['localConfigurationRegistryInstance':localConfigurationRegistryInstance]
    }

    def save = {
        def localConfigurationRegistryInstance = new LocalConfigurationRegistry(params)
        if(!localConfigurationRegistryInstance.hasErrors() && localConfigurationRegistryInstance.save()) {
            flash.message = "LocalConfigurationRegistry ${localConfigurationRegistryInstance.id} created"
            redirect(action:show,id:localConfigurationRegistryInstance.id)
        }
        else {
            render(view:'create',model:[localConfigurationRegistryInstance:localConfigurationRegistryInstance])
        }
    }
}
